package com.wizz.trade.information.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.wizz.trade.information.dto.page.TrademarkPageDto;
import com.wizz.trade.information.entity.Trademark;
import com.wizz.trade.information.mapper.TrademarkMapper;
import com.wizz.trade.information.service.TrademarkService;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;

import com.wizz.trade.common.PageVo;
import com.wizz.trade.util.PageUtil;
import org.apache.commons.lang3.StringUtils;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.List;
import java.util.Map;
import java.util.Objects;

/**
 * <p>
 * 商标表 服务实现类
 * </p>
 *
 * @author fyftless
 * @since 2023-04-02 04:26:06
 */
@Service
public class TrademarkServiceImpl extends ServiceImpl<TrademarkMapper, Trademark> implements TrademarkService {

    @Resource
    private TrademarkMapper trademarkMapper;


    @Override
    public void addTrademark(Trademark trademark) {
        trademarkMapper.insert(trademark);
    }

    @Override
    public void updateTrademark(Trademark trademark) {
        trademarkMapper.updateById(trademark);
    }

    @Override
    public void deleteTrademark(Integer id) {
        trademarkMapper.deleteById(id);
    }

    @Override
    public PageVo<Trademark> getPage(TrademarkPageDto trademarkPageDto) {
        LambdaQueryWrapper<Trademark> queryWrapper = new LambdaQueryWrapper<>();
        queryWrapper.eq(!Objects.isNull(trademarkPageDto.getVariety()),Trademark::getVariety,trademarkPageDto.getVariety());
        queryWrapper.like(StringUtils.isNotBlank(trademarkPageDto.getName()), Trademark::getName, trademarkPageDto.getName());
        IPage<Trademark> page = trademarkMapper.selectPage(PageUtil.initPage(trademarkPageDto), queryWrapper);
        return new PageVo<>(page);
    }

    @Override
    public List<Trademark> getAll() {
        return trademarkMapper.selectList(null);
    }

    @Override
    public List<Map<Integer, String>> getNames(Integer varietyId) {
        return trademarkMapper.getNames(varietyId);
    }

    @Override
    public List<Map<Integer, String>> getOptions(Integer varietyId) {
        return trademarkMapper.getOptions(varietyId);
    }

}
